﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLKDS.DTO;

namespace QLKDS.DAL
{
    public class ExportBookDetailManager
    {
        public IList<ExportBookDetail> ListExportBookDetail()
        {
            List<ExportBookDetail> listdata=new List<ExportBookDetail>();
            using (var db = new QLKDSDataContext())
            {
                listdata = db.ExportBookDetails.ToList();
                
            }
            return listdata;
        }
    

        public void CreateExportBookDetail(ExportBookDetail ExportBookDetail)
        {
            using (var db = new QLKDSDataContext())
            {
                db.ExportBookDetails.InsertOnSubmit(ExportBookDetail);

                db.SubmitChanges();
               
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="exportBookDetail"></param>
        public void UpdateExportBookDetail(ExportBookDetail exportBookDetail)
        {
            using (var db = new QLKDSDataContext())
            {
                var _exportBookDetail = db.ExportBookDetails.Single(d => d.Id.Equals(exportBookDetail.Id));
                _exportBookDetail.BookId = exportBookDetail.BookId;
                _exportBookDetail.ExportId = exportBookDetail.ExportId;
                _exportBookDetail.Price = exportBookDetail.Price;
                _exportBookDetail.Quantity= exportBookDetail.Quantity;
                _exportBookDetail.DiscountPercent = exportBookDetail.DiscountPercent;
                _exportBookDetail.TotalPrice = exportBookDetail.TotalPrice;
                _exportBookDetail.StoreId = exportBookDetail.StoreId;
                db.SubmitChanges();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void DeleteExportBookDetail(int id)
        {
            using (var db = new QLKDSDataContext())
            {
                var _ExportBookDetail = db.ExportBookDetails.Single(d => d.Id.Equals(id));

                db.ExportBookDetails.DeleteOnSubmit(_ExportBookDetail);
                db.SubmitChanges();
            }
        }



     
    }
}
